package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Claim;
import cn.wolfcode.crm.mapper.ClaimMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClaimService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class ClaimServiceImpl implements IClaimService {

    @Autowired
    private ClaimMapper claimMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        claimMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Claim selectByPrimaryKey(Long id) {
        return claimMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Claim> selectAll() {
        return claimMapper.selectAll();
    }

    @Override
    public void saveOrUpdate(Claim entity) {
        if (entity.getId() != null){
            claimMapper.updateByPrimaryKey(entity);
        }else {
            claimMapper.insert(entity);
        }
    }



    @Override
    public PageResult query(QueryObject qo) {
        int total = claimMapper.query4Count(qo);
        if(total == 0 ){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Claim> rows = claimMapper.query4List(qo);
        return new PageResult(total,rows);
    }

    public void changeClaimState(Long id) {
        claimMapper.changeClaimState(id);
    }


    /*@Override
    public PageResult claimlist(QueryObject qo) {
        return null;
    }*/
}
